<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>添加删除学员信息</title>
    </head>
    <body>
        <div>
            <table id="table">
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>年龄</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(user,index) in stu">
                        <td>{{index+1}}</td>
                        <td>{{user.name}}</td>
                        <td>{{user.age}}</td>
                        <td><button @click="remove(index)">移除</button></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input id="name" v-model="user.name"></td>
                        <td><input id="age" v-model="user.age"></td>
                        <td><button @click="insert">添加</button></td>
                    </tr>
                </tbody>
            </table>  
        </div>  

        <script type="text/javascript" src="./js/vue.js"></script>

        <script type="text/javascript">
            new Vue({
                el:'#table',
                data:{
                    user:{name:'',age:''},
                    stu:[
                        {'name': '张三', 'age': 17},
                        {'name': '里斯', 'age': 18},
                        {'name': '王五', 'age': 19}
                    ]
                },
                methods:{
                
                    insert:function(){
                        this.stu.push(this.user)
                    },
                    remove:function(index){
                        this.stu.splice(index,1)
                    }  
                }
            })
        </script>
    </body>
</html>
